/**
 * 
 */
package com.cplsystems.incidencias.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.cplsystems.incidencias.business.Servicios;
import com.cplsystems.incidencias.dao.ServicioDAO;

/**
 * @author César Palalía López (csr.plz@aisa-automation.com)
 * 
 */
@Repository
public class ServicioDAOImpl extends HibernateDaoSupport implements ServicioDAO {

	@Autowired
	public void init(final SessionFactory sessionFactory)
			throws DataAccessException {
		setSessionFactory(sessionFactory);
	}

	@SuppressWarnings("unchecked")
	@Transactional(readOnly = true)
	public List<Servicios> getAll() {
		List<Servicios> servicios = getHibernateTemplate().find(
				"FROM Servicios as s ");
		return servicios.size() > 0 ? servicios : null;
	}

	@Transactional
	public void save(Servicios servicio) {
		getHibernateTemplate().saveOrUpdate(servicio);
	}

	@Transactional
	public void delete(Servicios servicio) {
		getHibernateTemplate().delete(servicio);
	}

}
